﻿package com.question.view;

import com.question.Design.CommandFactory;
import com.question.entity.User;
import com.question.utils.InputOutUtils;
import com.question.view.command.CommandList;
import com.question.view.command.ICommand;



public class Application {
	private static User user; 
	public static User getUser() {
		return user;
	}
	public static void setUser(User user) {
		Application.user = user;
	}
	public static void main(String[] args) {
		InitApplication.init();
		InputOutUtils.print(Configure.WELCOME);
		//获得工厂对象
		CommandFactory commandFactory = CommandFactory.getCommandFactory();
		while(true) {
			try {
				String inCmd = InputOutUtils.inputString("",true);
				//当转换失败会发生异常
				CommandList cmd = CommandList.valueOf(inCmd.trim().toUpperCase());
				ICommand command = commandFactory.buildCommand(cmd, user);
				command.exec();
			}catch(IllegalArgumentException e) {
				InputOutUtils.print(Configure.HELPTIPS);
			}catch (Exception e) {
				InputOutUtils.print("查询失败");
			}
		}
		
	}
}
